package com.yls.except.util;

import com.yls.except.util.img.GetImgUrl;

import java.text.DecimalFormat;
import java.util.*;

/**
 * Created by Administrator on 2016/8/1.
 */
public class ValueJude {
    /**
     * 获取去除-后的uuid
     *
     * @return
     */
    public static String getUuid() {
        String uuid = UUID.randomUUID() + "";
        uuid = uuid.replace("-", "");
        return uuid;
    }

    /**
     * 获取图片的完整地址
     *
     * @param filepath 文件地址
     * @param imgpath  图片类型地址
     * @return 图片的完整地址
     */
    public static String getImgPath(String filepath, String imgpath) {
        if (StringIsempty.isallempty(imgpath))
            return "";
        if ((imgpath.length() > 7 && !imgpath.substring(0, 7).equals("http://") && !imgpath.substring(0, 8).equals("https://")) || imgpath.length() <= 7)  //判断图片地址是否已http或https开头
            imgpath = filepath + imgpath;
        return imgpath;
    }

    /**
     * 根据连续签到次数获取前端显示值
     *
     * @param seriescount 连续签到次数
     * @return app端显示值
     */
    public static String getSignInStr(int seriescount) {
        int start = 1;
        int end = 1;
        if (seriescount < 3) {
            start = 3 - seriescount;
            end = 3;
        } else if (seriescount < 6) {
            start = 6 - seriescount;
            end = 6;
        } else if (seriescount < 9) {
            start = 9 - seriescount;
            end = 9;
        }
        String str = "再签" + start + "天，可获得连续签到" + end + "天奖励";
        return str;
    }

    public static Map<String, Object> getImgpathMap(String imgaddress, String imgtype, int type, String type_id, String reqip, long time) {
        imgaddress = imgaddress.replace(imgtype, "");
        Map<String, Object> imgmap = new HashMap<String, Object>();
        imgmap.put("img_type", type);
        imgmap.put("type_id", type_id);
        imgmap.put("img_address", imgaddress);
        imgmap.put("addtime", time);
        imgmap.put("addip", reqip);
        imgmap.put("isdisabled", 1);
        return imgmap;
    }

    public static Map<String, Object> getChatImgPath(List<Map<String, Object>> chat, String imgfile, Map<String, Object> store, String type) {
        if (chat == null || chat.size() <= 0) {//判断聊天图片是否为空
            store.put(type, "");
        } else {
            String chatimg = chat.get(0).get("img_address") + ""; //获取聊天头像图片地址
            chatimg = ValueJude.getImgPath(imgfile, chatimg); //获取聊天图片地址完整路径
            store.put(type, chatimg);  //聊天图片地址
        }
        return store;
    }

    public static Map<String, Object> getShowImgPath(List<Map<String, Object>> list, String imgfile, Map<String, Object> store, String type) {
        if (list == null || list.size() <= 0) {//判断聊天图片是否空
            store.put(type, new ArrayList<Object>());
        } else {
            List<Object> showlist = GetImgUrl.getImgList(list, imgfile); //获取店铺显示图片地址完整路径
            store.put(type, showlist);  //聊天图片地址
        }
        return store;
    }


    /**
     * 获取支付类型
     *
     * @param paytype 支付类型
     * @return 支付类型
     */

    public static String getPayType(String paytype) {
        if ("1".equals(paytype))
            paytype = "余额";
        else if ("2".equals(paytype))
            paytype = "支付宝";
        else if ("3".equals(paytype))
            paytype = "微信";
        else if ("4".equals(paytype))
            paytype = "银联";
        else if ("5".equals(paytype))
            paytype = "百度钱包";
        else if ("6".equals(paytype))
            paytype = "易宝支付";
        else
            paytype = "";
        return paytype;
    }

    /**
     * 将价格保存两位小数
     *
     * @param money 价格
     * @return 价格
     */
    public static String getDecima(String money) {
        if (StringIsempty.isallempty(money))
            return "";
        DecimalFormat df = new DecimalFormat("0.00");
        double d = Double.parseDouble(money) / 100;
        return df.format(d);
    }

    /**
     * 保留小数位数
     *
     * @param money 价格
     * @return 价格
     */
    public static String getDecimaNum(String money, int num) {
        if (StringIsempty.isallempty(money))
            return "";
        String decima = "";
        if (num > 0) {
            for (int i = 0; i < num; i++) {
                if (i == 0)
                    decima += ".0";
                else
                    decima += "0";
            }
        }
        DecimalFormat df = new DecimalFormat("0" + decima);
        double d = Double.parseDouble(money) / 100;
        String returnstr = df.format(d);
        if (!StringIsempty.isallempty(decima)) {
            if (decima.equals("." + returnstr.split("\\.")[1])) {
                returnstr = returnstr.split("\\.")[0];
            }
        }
        return returnstr;
    }

    /**
     * 获取积分状态
     * 积分获取类型（1：签到  2：分享   3：购买平台自营产品 4：兑换星点  5：兑换云点  6：兑换金额）
     *
     * @param state 积分状态码
     * @return 积分状态
     */
    public static String getIntegralState(String state) {
        if (StringIsempty.isallempty(state))
            return "";
        if ("1".equals(state))
            state = "签到";
        else if ("3".equals(state))
            state = "购买平台自营产品";
        else if ("4".equals(state))
            state = "兑换星点";
        else if ("5".equals(state))
            state = "兑换云点";
        else if ("6".equals(state))
            state = "兑换金额";
        else if ("7".equals(state))
            state = "分享到qq";
        else if ("8".equals(state))
            state = "分享到qq空间";
        else if ("9".equals(state))
            state = "分享到微信";
        else if ("10".equals(state))
            state = "分享到朋友圈";
        else if ("11".equals(state))
            state = "分享到微博";
        return state;
    }

    public static int randnum() {
        boolean[] bol = new boolean[11];
        for (int i = 1; i < 11; i++)
            bol[i] = false;
        bol[0] = true;
        for (int i = 0; i < 10; ) {
            double a = Math.random() * 10;
            a = Math.ceil(a);
            int randomNum = new Double(a).intValue() % 11;
            if (bol[randomNum])
                continue;
            bol[randomNum] = true;
            i++;
            return randomNum;
        }
        return 0;
    }

    /**
     * 根据订单状态获取订单状态说明
     * @param indent_state 订单状态
     */
    public static String getIndentStateDesc(String indent_state) {
        if("1".equals(indent_state))
            return "等待买家付款";
        else if("2".equals(indent_state))
            return "等待商家发货";
        else if("3".equals(indent_state))
            return "等待买家收货";
        else if("4".equals(indent_state))
            return "已完成";
        else if("5".equals(indent_state))
            return "已取消";
        else
            return "订单完成";
    }
}
